package pl.edu.agh.student.janikhankus.tree;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * Class which represents grammar tree. Contains list of Productions which corresponds to right side of production.
 * 
 * @author Jaroslaw Janik
 */
public class Grammar {

	private LinkedList<Production> productionList = new LinkedList<Production>();
	private Map<String, String> temporaryProductions = new HashMap<String, String>();

	/**
	 * Gets right side of production.
	 * 
	 * @return List of productions.
	 */
	public LinkedList<Production> getProductionList() {
		return productionList;
	}

	/**
	 * Sets right side of production.
	 * 
	 * @param productionList List of productions.
	 */
	public void setProductionList(LinkedList<Production> productionList) {
		this.productionList = productionList;
	}
	
	/**
	 * Adds produciton to the tree.
	 * 
	 * @param production Production to add.
	 */
	public void addProduction(Production production) {
		
		productionList.add(production);
	}
	
	/**
	 * Adds temporary start production as a root of hierarchy.
	 * 
	 * @param production Production to add.
	 */
	public void addStartProduction(Production production) {
		
		productionList.addFirst(production);
	}
	
	/**
	 * Adds temporary production to hierarchy.
	 * 
	 * @param production Production to add.
	 */
	public void addTemporaryProduction(Production production) {
		temporaryProductions.put(production.getLeft().getName(), production.getRight().get(0).getName());
	}
	
	/**
	 * Returns all temporary productions.
	 * 
	 * @return Map of productions.
	 */
	public Map<String, String> getTemporaryProductions() {
		return temporaryProductions;
	}
}
